import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

class Manga  {
	
	Document mangaInfo(Connection connex){
		connex.timeout(30000);
		Document res = new Document("");
		try {
			Document res0 = connex.get();
			res=res0;
		} catch(Exception e){System.out.println("L'URL utilisée est inaccessible");}
		return res;
		
	}
	
	String mangaName;
	int mangaRelease; 
	String mangaAuthor; 
	String mangaArtist ;
	String[] mangaGenres; 
	String mangaSum;
	String mangaStatus; 
	String mangaRankingSentence;
	String mangaRanking; 
	String mangaRatingSentence; 
	String mangaRating;

	
	Manga (String mangaUrl, String mangaName1){
		
		Connection mangaInfoConnect = Jsoup.connect(mangaUrl);
		
		
		Element divTitle = mangaInfo(mangaInfoConnect).getElementById("title");
		Element divSeriesInfo = mangaInfo(mangaInfoConnect).getElementById("series_info");
		Element titleTab = divTitle.getElementsByTag("table").first().child(0).child(1);
		
		//mangaName = divTitle.getElementsByTag("h2").first().text().replaceAll("Manga Online", "").replaceAll("Read", "").trim();
		mangaName = mangaName1;
		mangaRelease = Integer.parseInt(titleTab.child(0).text());
		mangaAuthor = titleTab.child(1).text();
		mangaArtist = titleTab.child(2).text();
		mangaGenres = titleTab.child(3).text().split(",");
		mangaSum = divTitle.getElementsByClass("summary").html();
		mangaStatus = divSeriesInfo.getElementsByClass("data").get(0).text().substring(8);
		mangaRankingSentence = divSeriesInfo.getElementsByClass("data").get(1).text();
		mangaRanking = mangaRankingSentence.substring(mangaRankingSentence.indexOf(":")+1,mangaRankingSentence.indexOf(",")).replaceAll("th","").trim();
		mangaRatingSentence = divSeriesInfo.getElementsByClass("data").get(2).text();
		mangaRating = mangaRatingSentence.substring(mangaRatingSentence.indexOf(":")+1,mangaRatingSentence.indexOf("/")).replaceAll("Average","").trim();
	}
	
}